package com.gitee.wsl.compose.chart.xy.bar.stack

import com.gitee.wsl.compose.chart.xy.bar.BarComposable

/**
 * Scope item to allow adding items to a [StackedVerticalBarPlot].
 */
 interface StackedVerticalBarPlotSeriesScope<X> {
    /**
     * Adds an item at the specified [x] axis coordinate, with a vertical extent [y], which will
     * be added to series elements at the same x-axis coordinate already added to the plot.
     * An optional [bar] can be provided to customize the Composable used to
     * generate the bar for this specific item.
     */
     fun item(x: X, y: Float, bar: BarComposable? = null)
}

class StackedVerticalBarPlotSeriesScopeImpl<X>(
    val defaultBar: BarComposable
) : StackedVerticalBarPlotSeriesScope<X> {

    val data: MutableMap<X, Pair<Float,BarComposable>> = mutableMapOf()

    override fun item(x: X, y: Float, bar: BarComposable?) {
        data[x] = Pair(y, bar ?: defaultBar)
    }
}